They are only interchangeable between tools in the same range by the same manufacturer.
For example all Milwaukee M12 (12V) tools can use any M12 battery (they come in 2Ah, 4Ah, and 6Ah) and M18 (18V) tools can use M18 batteries but they are not interchangeable between the two voltages. They even connect in entirely different ways to make sure there’s no mistaking which one fits which tool.